package com.qinggeng.project.system.controller;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.qinggeng.common.enums.CommonEnum;
import com.qinggeng.project.system.domain.GoodsGift;
import com.qinggeng.project.system.service.IGoodsGiftService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.project.system.domain.SysActivity;
import com.qinggeng.project.system.service.ISysActivityService;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.web.page.TableDataInfo;
/**
 * 系统活动Controller
 *
 * @author smallfish
 * @date 2021-01-12
 */
@RestController
@RequestMapping("/system/sysActivity")
public class SysActivityController extends BaseController
{
    @Autowired
    private ISysActivityService sysActivityService;
    @Autowired
    private IGoodsGiftService goodsGiftService;

    /**
     * 查询系统活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysActivity sysActivity)
    {
        startPage();
        List<SysActivity> list = sysActivityService.selectSysActivityList(sysActivity);
        return getDataTable(list);
    }

    /**
     * 导出系统活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:export')")
    @Log(title = "系统活动", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysActivity sysActivity)
    {
        List<SysActivity> list = sysActivityService.selectSysActivityList(sysActivity);
        ExcelUtil<SysActivity> util = new ExcelUtil<SysActivity>(SysActivity.class);
        return util.exportExcel(list, "sysActivity");
    }

    /**
     * 获取系统活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysActivityService.selectSysActivityById(id));
    }

    /**
     * 新增系统活动
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:add')")
    @Log(title = "系统活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysActivity sysActivity)
    {

        return toAjax(sysActivityService.insertSysActivity(sysActivity));
    }

    /**
     * 修改系统活动
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:edit')")
    @Log(title = "系统活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysActivity sysActivity)
    {
        return toAjax(sysActivityService.updateSysActivity(sysActivity));
    }

    /**
     * 删除系统活动
     */
    @PreAuthorize("@ss.hasPermi('system:sysActivity:remove')")
    @Log(title = "系统活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysActivityService.deleteSysActivityByIds(ids));
    }

    @GetMapping("/gift")
    public AjaxResult giftList(){
        return AjaxResult.success(sysActivityService.listActivityGiftDTO());
    }
}
